package com.maijinjie.admin.content.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.maijinjie.common.bean.Pagination;
import com.maijinjie.common.bean.StatusBean;
import com.maijinjie.admin.content.bean.CookListBean;
import com.maijinjie.admin.content.dao.CookListMapper;
import com.maijinjie.admin.content.field.CookListFields;
import com.maijinjie.admin.content.service.CookListService;
import com.maijinjie.common.service.impl.BaseServiceImpl;

/**
 * CookListServiceImpl
 * @author 罗正杰
 **/
@Service("cookListService")
public class CookListServiceImpl extends BaseServiceImpl implements CookListService{
	@Resource
	CookListMapper cookListMapper;
	
	@Override
	public CookListBean getBeanById(Integer id) throws Exception{
		if(null==id || 0>=id){
			return null;
		} else {
			return (CookListBean) getBeanById(cookListMapper, id);
		}
	}
	@Override
	public int count(Map<String, Object> params) throws Exception {
		return cookListMapper.count(params);
	}
	@Override
	public List<CookListBean> list(Map<String, Object> params) throws Exception {
		return (List<CookListBean>) cookListMapper.list(params);
	}
	@Override
	public StatusBean save(CookListBean bean, String createBy, Integer createUserId) throws Exception {
		Date currDate = new Date();
		//TODO 处理业务
		
		if(0<cookListMapper.save(bean)){
			return success("操作成功！");
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean update(CookListBean bean, String createBy, Integer createUserId) throws Exception {
		if(null!=bean){
			Date currDate = new Date();
			HashMap<String, Object> params = new HashMap<String, Object>();
			//TODO 处理业务
			
			if(cookListMapper.update(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean deleteById(Integer id) throws Exception {
		if(null!=id && 0<id){
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(CookListFields.id.toString(), id);
			if(cookListMapper.delete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public Pagination<CookListBean> list(Pagination<CookListBean> pagination) throws Exception {
		return (Pagination<CookListBean>) getPagination(cookListMapper, pagination);
	}
	@Override
	public StatusBean batchDelete(String ids) throws Exception {
		if(null!=ids && !"".equals(ids.trim())) {
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(CookListFields.id.toString(), ids);
			if(cookListMapper.batchDelete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public List<CookListBean> listAll() throws Exception {
		return (List<CookListBean>) cookListMapper.list(null);
	}
	@Override
	public Map<String, List> listAllByCateory(Map<String, Object> params)
			throws Exception {
		Map<String,List> map = new HashMap<String,List>();
		map.put("1", new ArrayList<CookListBean>());
		map.put("2", new ArrayList<CookListBean>());
		map.put("3", new ArrayList<CookListBean>());
		map.put("4", new ArrayList<CookListBean>());
		map.put("5", new ArrayList<CookListBean>());
		map.put("6", new ArrayList<CookListBean>());
		map.put("7", new ArrayList<CookListBean>());
		List<CookListBean> list = (List<CookListBean>) cookListMapper.list(params);
		for(CookListBean bean : list){
			map.get(bean.getWeekday()).add(bean);
		}
		return map;
	}
}
